<?php

/**
 * inscription actions.
 *
 * @package    sf_sandbox
 * @subpackage inscription
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class inscriptionActions extends sfActions
{
 /**
  * Executes index action
  * Formulaire d'inscription du user
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
  }

  /**
   * Confirmation d'inscription
   * @param sfWebRequest $request
   */
  public function executeConfirmation(sfWebRequest $request)
  {
  		if ($request->isMethod('POST'))
  		{
  			$oUser = Doctrine::getTable('Users')->findbyEmail($request->getPostParameter('mail'));
  			if (!isset($oUser[0]))
  				$this->erreur = 1;
  			
  			$oUser = $oUser[0];
 
  			$sKey = $request->getPostParameter('key');
  			if ($sKey === substr( md5( $oUser->ip . $oUser->email . $oUser->date_inscription ),0, 8) )
  			{
  				//User vérifié
  				$oUser->etat = 1;
  				$oUser->save();
  				
  				// On connecte l'utilisateur
				sfContext::getInstance()->getUser()->connect($oUser);
  			}
  			else
  			{
  				$this->erreur = 1;
  			}
  		}
  }

  /**
   * Formulaire de récupération de mot de passe
   * @param sfWebRequest $request
   */
  public function executeFindMdp(sfWebRequest $request)
  {
  		if ($this->getUser()->isAuthenticated())
  			$this->forward('@homepage');
  	
		if ($request->isMethod('POST'))
		{
			$oUser = Doctrine::getTable('Users')->findByEmail($request->getPostParameter('mail'))
			if (!$oUser[0])
			{
				$this->oUser = $oUser[0];
				SendMail::sendMdpOublie($this->oUser->id);
			}
			else
			{
				$this->erreur = 1;
			}
		}
  }
  
  /**
   * Check le mail en Ajax
   * @param sfWebRequest $request
   */
  public function executeAjaxCheckLogin(sfWebRequest $request)
  {
 		
  }
}
